package main

import (
	"fmt"

	"time"

	"git.oschina.net/sheldwu/redis"
)

func set(ch chan bool, no int) {

	r := redis.GetInstance("default")

	total := 1000
	begin := time.Now().UnixNano() / 1000000
	for i := 0; i < total; i++ {
		key := fmt.Sprintf("%d", i+total*no)
		val := fmt.Sprintf("%d", i)
		r.Set(key, val, 0)
		//val, err := status.Result()
		//fmt.Println(res)
		/*
			if err != nil {
				log.Fatal(err)
			}
		*/
	}
	end := time.Now().UnixNano() / 1000000
	d := end - begin
	fmt.Println(end, begin)
	qps := float64(total) / float64(d) * 1000
	fmt.Println(qps)
	fmt.Printf("chan %d over , qps is %f\n", no, qps)
	ch <- true
}

func main() {
	concurrenceCount := 20
	
	chSlice := make([]chan bool, concurrenceCount)
	RedisConfig := make(map[string]string)
	RedisConfig["default"] = "Res.Redis.SMSGateWay_data"
	redis.Init(RedisConfig)
	for i := 0; i < concurrenceCount; i++ {
		chSlice[i] = make(chan bool)
		go set(chSlice[i], i)
		//fmt.Println(i)
	}

	for i := 0; i < concurrenceCount; i++ {
		//	fmt.Println("waiting for redis action be done ")
		<-chSlice[i]
		//fmt.Println(a)
	}

}
